home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / PMENU.C < prev    next >
C/C++ Source or Header  |  1991-12-15  |  7KB  |  186 lines

  1. /**********************************************************/
  2. /* File Id.                  Pmenu.C                      */
  3. /* Author.                   Stan Milam.                  */
  4. /* Date Written.             03/10/89.                    */
  5. /* Last Modified.                                         */
  6. /*                                                        */
  7. /*          (c) Copyright 1989, 1990 by Stan Milam        */
  8. /*                                                        */
  9. /* Comments:  This file contains the functions to make &  */
  10. /* accept input from pop-up menus.                        */
  11. /**********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15. #include <conio.h>
  16. #include "pcw.i"
  17. #include "pcwproto.h"
  18. #include "menu.h"
  19. #include "keys.h"
  20.  
  21. static void chg_bar_pos(PMNUTYPE *menu, int new_pos);
  22.  
  23. /**********************************************************/
  24. /*                         MakePmenu                      */
  25. /*                                                        */
  26. /* This function will take as an argument a pointer to a  */
  27. /* variable of PMNUTYPE and use the information passed */
  28. /* to build a pop-up menu. It will call wframe() to frame */
  29. /* a window for the menu and return a normal window win-  */
  30. /* dow pointer.                                           */
  31. /**********************************************************/
  32.  
  33. WNDPTR *makepmenu(PMNUTYPE *menu) {
  34.  
  35.     int    row, cols;
  36.     PMNUFLDS *temp;
  37.     MENU_WND    *pwnd;
  38.  
  39.     pwnd = &menu->pwnd;
  40.     setborder(pwnd->btype);                      /* Set border */
  41.     titlecolor(pwnd->tfclr, pwnd->tbclr);        /* Menu title color */
  42.     bordercolor(pwnd->bfclr, pwnd->bbclr);       /* Border color */
  43.  
  44.     pwnd->wnd = wframe(pwnd->urow,pwnd->ucol,    /* Frame the window */
  45.                        pwnd->lrow,pwnd->lcol,
  46.                        pwnd->fcolor,pwnd->bcolor);
  47.     if (pwnd->wnd == (WNDPTR *) NULL)            /* Check for good */
  48.        return(NULL);                             /* Return */
  49.  
  50.     pwnd->urow = pwnd->wnd->urow;                /* Adjust menu */
  51.     pwnd->ucol = pwnd->wnd->ucol;
  52.     pwnd->lrow = pwnd->wnd->lrow;
  53.     pwnd->lcol = pwnd->wnd->lcol;
  54.  
  55.     wtitle(pwnd->wnd,pwnd->tvloc,pwnd->thloc,pwnd->title);
  56.     temp = menu->plist;
  57.  
  58.     /* Write the menu items */
  59.  
  60.     row = 1;
  61.     while (*temp->item != (char) NULL && temp->item != NULL) {
  62.         wputs(pwnd->wnd, row, CENTER, temp->item);
  63.         temp++;
  64.         row++;
  65.     }
  66.  
  67.     cols = (pwnd->lcol - pwnd->ucol) - 1;
  68.     w_chg_attr(pwnd->wnd,1+menu->bar_pos,1,pwnd->cfclr,pwnd->cbclr,cols);
  69.     return(pwnd->wnd);
  70. }
  71.  
  72. /**********************************************************/
  73. /*                        PmenuInput                      */
  74. /*                                                        */
  75. /* This function will take as an argument a pointer to    */
  76. /* type PMNUTYPE and determine if a menu selection was */
  77. /* made from the keyboard or from the mouse.  The up and  */
  78. /* down arrow keys will move the selection bar thru the   */
  79. /* menu selections.  Pressing the Enter Key will make the */
  80. /* selection.  Pressing the Esc key will return to caller */
  81. /* with the Esc character code.  Using the mouse: Left key*/
  82. /* will select what was pointed to.  Right Key will be the*/
  83. /* same as escape.                                        */
  84. /**********************************************************/
  85.  
  86. int pmenuinput(PMNUTYPE *menu) {
  87.  
  88.    int  row, col, bstatus;
  89.    int  select;
  90.    int  select_count = 0;
  91.    int  ch;
  92.    PMNUFLDS *temp;
  93.    MENU_WND *pwnd;
  94.  
  95.    temp = menu->plist;
  96.    pwnd = &menu->pwnd;
  97.    for (select=0;temp[select].select_key!='\0';select++);
  98.    select_count = select - 1;
  99.  
  100.    if (mpresent) hide_mouse();
  101.    re_order(pwnd->wnd, NORMAL);
  102.    if (mpresent) show_mouse();
  103.    for (;;) {                                    /* Loop forever */
  104.        ch = keyin();
  105.        switch(ch) {
  106.           case ENTER :
  107.           case BOTH_MOUSE_KEY :
  108.              return(temp[menu->bar_pos].select_key);
  109.           case ESC :
  110.              return(ESC);
  111.           case RITEARROW :
  112.              return ( RITEARROW );
  113.           case LEFTARROW :
  114.              return ( LEFTARROW );
  115.           case RITE_MOUSE_KEY :
  116.              return ( ESC );
  117.           case LEFT_MOUSE_KEY :
  118.              get_mpos(&row,&col,&bstatus);
  119.              if ((row >= pwnd->wnd->urow+1 && row <= pwnd->wnd->lrow-1) &&
  120.                  (col >= pwnd->wnd->ucol+1 && col <= pwnd->wnd->lcol-1)) {
  121.                   select = (row - pwnd->wnd->urow) - 1;
  122.                   if (select > select_count) break;
  123.                   if (select == menu->bar_pos)
  124.                      return(temp[select].select_key);
  125.                   hide_mouse();
  126.                   chg_bar_pos(menu,select);
  127.                   show_mouse();
  128.                   return(temp[select].select_key);
  129.              }
  130.              break;
  131.           case DOWNARROW :
  132.           case TAB:
  133.           case PGDN:
  134.              select = menu->bar_pos + 1;
  135.              if (select > select_count) select = 0;
  136.              if (mpresent) hide_mouse();
  137.              chg_bar_pos(menu,select);
  138.              if (mpresent) show_mouse();
  139.              break;
  140.           case SHFTTAB :
  141.           case UPARROW :
  142.           case PGUP:
  143.              select = menu->bar_pos - 1;
  144.              if (select < 0) select = select_count;
  145.              if (mpresent) hide_mouse();
  146.              chg_bar_pos(menu,select);
  147.              if (mpresent) show_mouse();
  148.              break;
  149.            default :
  150.               if ( isalpha( ch ) ) ch = toupper(ch);
  151.               for (select = 0;select <= select_count; select++) {
  152.                   if (ch == toupper(menu->plist[select].select_key)) {
  153.                      if (select == menu->bar_pos)
  154.                         return(temp[select].select_key);
  155.                      if (mpresent) hide_mouse();
  156.                      chg_bar_pos(menu,select);
  157.                      if (mpresent) show_mouse();
  158.                      return(temp[select].select_key);
  159.                   }
  160.               }
  161.         }
  162.    }
  163. #ifndef __TURBOC__
  164.    return ( 0 );
  165. #endif
  166. }
  167.  
  168. /**********************************************************/
  169. /*                       chg_bar_pos()                    */
  170. /*                                                        */
  171. /* Used to change the bar position on the pop-up menus    */
  172. /**********************************************************/
  173.  
  174. static void chg_bar_pos(PMNUTYPE *menu, int new_pos) {
  175.  
  176.    int      cols;
  177.    MENU_WND *pwnd;
  178.  
  179.    pwnd = &menu->pwnd;
  180.    cols = (pwnd->wnd->lcol - pwnd->wnd->ucol) - 1;
  181.    w_chg_attr(pwnd->wnd,1+menu->bar_pos, 1, pwnd->fcolor, pwnd->bcolor, cols);
  182.    w_chg_attr(pwnd->wnd,1+new_pos, 1, pwnd->cfclr, pwnd->cbclr, cols);
  183.    menu->bar_pos = new_pos;
  184. }
  185.  
  186.